package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.model.PersonalRankModel;
import com.ldc.wandroid.server.ApiServer;

import java.util.List;

public class PersonalRankViewModel extends ViewModelBase {
    private final ApiServer apiServer;
    private final MutableLiveData<List<PersonalRankModel.DatasBean>> coinRank = new MutableLiveData<>();

    public LiveData<List<PersonalRankModel.DatasBean>> getCoinRank() {
        return coinRank;
    }

    public PersonalRankViewModel() {
        this.apiServer = Api2Request.getInstance().createServer(ApiServer.class);
    }


    public void getCoinRankReq(int index) {
        apiRequest(apiServer.getCoinRank(index), (status, result, throwable) -> {
            if (status) {
                coinRank.setValue(result.getData().getDatas());
            } else {
                coinRank.setValue(null);
            }
        });
    }
}
